package day10.Map;

/*
 * Author: JacksonCoder
 * FileName: ConcurrentHashMapDemo
 * Version: 1.0.0
 * Date: 2025/4/17
 */

import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapDemo {

    public static void main(String[] args) {

        ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();

        // 添加元素
        map.put("Java", 1);
        map.put("Python", 2);
        map.putIfAbsent("Go", 3); // 如果没有才添加

        // 遍历
        map.forEach((key, value) -> {
            System.out.println(key + " = " + value);
        });

        // 更新值
        map.compute("Java", (k, v) -> v + 1); // 更新值
        System.out.println("Java = " + map.get("Java"));

    }

}
